<?php

define('_APP_PATH',  dirname(__FILE__) . DIRECTORY_SEPARATOR);

define('_APP_URL', '/app/');

define('_APP_CONF',  _APP_PATH . 'config' . DIRECTORY_SEPARATOR . 'main.php');
/**
 * 
 */
require_once 'core/init.php';
/**
 * 
 * Application run class
 * @author taras
 *
 */
class appRun
{
    /**
     *
     * @var gInit
     */
    var $Gepard = null;

    function  __construct() {
        $this->Gepard = new gInit();
        // parsing configuration file
        $this->Gepard->app->parseConf(_APP_CONF);      
        // preparing request data
        $this->Gepard->request->prepare();
        // connection to the database
        //$this->Gepard->dbo->connect();
        // loading cms main object
        // preparing view layout
    }

    function __destruct()
    {
        $this->stop();
        exit;
    }

    public function listen($controller = null, $action = null, $options = null)
    {
        try
        {
            gRequest::parseRequest();
            $this->Gepard->app->bindComponent('cms');
            $this->Gepard->cms->dispatch(gRequest::getController(),  gRequest::getAction());
        }
        catch (gException $e)
        {
            print $e->getMessage();
        }
    }

    public function render()
    {
        try
        {
            $this->Gepard->view->setLayout();
            $this->Gepard->view->render();
        }
        catch (gException $e)
        {
            print $e->getMessage();
        }
    }
    
    public function stop()
    {
        $this->Gepard->dbo->disconnect();
    }
}